import { Person } from './../interface';
import { Provide, Scope, ScopeEnum } from '@midwayjs/core';
import { LeaveBill, LeaveBillStateEnum, LeaveTypeEnum } from '../interface';

@Provide()
@Scope(ScopeEnum.Singleton)
export class Mockdb {
  personDB: Array<Person> = [];
  leaveBillDB: Array<LeaveBill> = [];

  constructor() {
    this.personDB = [
      { id: 0, name: 'zhangsan', age: 10 },
      { id: 1, name: 'lisi', age: 12 },
      { id: 2, name: 'wangwu', age: 32 },
    ];
    this.leaveBillDB = [
      {
        leaveBillId: Date.now(),
        reason: 'for a trip to the town',
        leaveType: LeaveTypeEnum.annual,
        leaveTimeFrom: new Date('2023-02-02'),
        leaveTimeTo: new Date('2023-02-04'),
        applier: 'zhangsan',
        auditor: 'libai',
        leaveBillState: LeaveBillStateEnum.approved,
        auditorWords: 'go ahead',
      },
      {
        leaveBillId: Date.now() + 1,
        reason: '...',
        leaveType: LeaveTypeEnum.issue,
        leaveTimeFrom: new Date('2023-03-02'),
        leaveTimeTo: new Date('2023-03-03'),
        applier: 'zhangsan',
        auditor: 'libai',
        leaveBillState: LeaveBillStateEnum.saved,
        auditorWords: null,
      },
    ];
  }
}
@Provide()
@Scope(ScopeEnum.Singleton)
export class BillCodeGenerator {
  personIndex = 3;
  /**
   * generate
   */
  public generate() {
    const old = this.personIndex;
    this.personIndex++;
    console.log(`流水号${old}将被使用，下一个流水号为${this.personIndex}`);
    return old;
  }
}
